package cn.wolfcode.crm.web.controller;


import cn.wolfcode.crm.page.PageResult;
import cn.wolfcode.crm.query.SystemLogQueryObject;
import cn.wolfcode.crm.service.ISystemLogService;
import cn.wolfcode.crm.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Arrays;

@Controller
@RequestMapping("systemLog")
public class SystemLogController {

    @Autowired
    private ISystemLogService systemLogService;


    @RequestMapping("")
    public String index() {

        return "systemLog";
    }

    @RequestMapping("list")
    @ResponseBody
    public PageResult list(SystemLogQueryObject qo) {

        PageResult pageResult = systemLogService.query(qo);
        System.out.println(qo.getBeginDate()+"~~"+qo.getEndDate());
        return  pageResult;
    }

    @RequestMapping("reload")
    @ResponseBody
    public JsonResult reload() {
        JsonResult result = new JsonResult();
        try{
            systemLogService.reload();
            result.setMessage("加载成功");
        }catch (Exception e){
            e.printStackTrace();
            result.mark("加载失败啦!");
        }
        return result;
    }

    @RequestMapping(value="remove", method = {RequestMethod.POST})
    @ResponseBody
    public JsonResult remove(@RequestBody Long[] ids) {

        System.out.println(Arrays.toString(ids));

        JsonResult result = new JsonResult();
        if (ids != null) {
            try {
                    systemLogService.remove(ids);
                    result.setMessage("删除成功");

            } catch (Exception e) {
                e.printStackTrace();
                result.mark("删除失败");
            }

        }
        return result;
    }
}